package com.nowcoder.community.dao;

import com.nowcoder.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

/**
 * @Author Cl
 * @Date 2024-2024/4/28  8:56
 * @Description 登录凭证的Mapper接口
 */
@Mapper
public interface LoginTicketMapper {

    /**插入记录*/
    @Insert({"insert into login_ticket(user_id,ticket,status,expired) ",
             "values (#{userId},#{ticket},#{status},#{expired})"})
    @Options(useGeneratedKeys = true , keyProperty = "id")
    int insertLoginTicket(LoginTicket loginTicket);

    /**根据登录凭证查找记录*/
    @Select({"select id,user_id,ticket,status,expired ",
             "from login_ticket where ticket=#{ticket}"})
    LoginTicket selectByTicket(String ticket);

    /**更新登录凭证状态*/
    @Update({"<script>",
                "update login_ticket set status=#{status} where ticket=#{ticket} ",
                "<if test =\"ticket!=null\"> ", // 这个if其实没什么用,只是演示一下这里可以用脚本标签
                    "and 1=1",
                "</if>",
            "</script>"
    })
    int updateStatus(String ticket , int status);
}
